package giit.computerbase.action;

import giit.computerbase.server.UserServer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

/**
 * User: tum0r
 * Package Name: ${PACKAGE_NAME}
 * Time: 2018-11-30 Friday 11:22:31
 */
public class DeleteUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String user = request.getParameter("name");
        String toPath = "warn.jsp?";
        if (user != null && !user.equals("")) {
            UserServer userServer = new UserServer();
            if (userServer.delete(user)) {
                toPath += ("state=panel-primary&title=" + URLEncoder.encode("用户删除") + "&context=" + URLEncoder.encode("删除 " + user + " 成功") + "&preview=manager.jsp");
            } else {
                toPath += ("state=panel-danger&title=" + URLEncoder.encode("用户删除") + "&context=" + URLEncoder.encode("删除 " + user + " 失败") + "&preview=manager.jsp");
            }
        } else {
            toPath += ("state=panel-danger&title=" + URLEncoder.encode("用户删除") + "&context=" + URLEncoder.encode("删除失败，信息不完整") + "&preview=manager.jsp");
        }
        response.sendRedirect(toPath);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
